import Vue from 'vue'
import Router from 'vue-router'
// 二级路由
import Map from './views/common/Map'
import Menu from './views/pages/menu/Menu'
// 一级路由
const Home = () => import('./views/pages/home/Home')
const Activity = () => import('./views/pages/activity/Activity')
const Admin = () => import('./views/pages/Admin')
const About = () => import('./views/pages/About')

Vue.use(Router)

export default new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: '*',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: Home,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/activity',
      name: 'activity',
      component: Activity,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/admin',
      name: 'admin',
      component: Admin,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/about',
      name: 'about',
      component: About,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/menu/:id',
      name: 'menu',
      component: Menu,
      meta: {
        showFooter: true
      }
    },
    {
      path: '/map',
      name: 'map',
      component: Map,
      meta: {
        showFooter: false
      }
    }
  ],
  // 滚动行为
  scrollBehavior (to, from, savedPosition) { // scrollBehavior 方法接收 to 和 from 路由对象。第三个参数 savedPosition 当且仅当 popstate 导航 (通过浏览器的 前进/后退 按钮触发) 时才可用。
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})
